package com.example.controller.buyer;

import com.example.entity.OrderReturnApply;
import com.example.param.OrderSearchParams;
import com.example.service.OrderReturnApplyService;
import com.example.vo.LoginUser;
import com.example.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

/**
 * @author circle48
 */
@RestController
@Api(tags = "买家端,订单退款接口")
@RequestMapping("/buyer/order/refund")
public class OrderReturnBuyerController {
    @Resource
    private OrderReturnApplyService orderReturnApplyService;

    @ApiOperation(value = "申请退款")
    @ApiImplicitParam(name = "orderReturnApply", value = "订单退货申请信息", required = true, dataType = "OrderReturnApply", paramType = "body")
    @PostMapping("/add")
    public Result createReturnApply(@Valid @RequestBody OrderReturnApply orderReturnApply) {
        return orderReturnApplyService.createReturnApply(orderReturnApply);
    }

    @ApiOperation(value = "查询用户售后订单列表")
    @GetMapping("/query")
    public Result queryMyRefundOrder(OrderSearchParams orderSearchParams) {

        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
        String username = loginUser.getUser().getNickName();
        return orderReturnApplyService.getMyRefundOrders(username,orderSearchParams);
    }

    @ApiOperation(value = "更新退货单的物流单号")
    @PostMapping("/updateDeliverySn")
    public Result updateReturnDeliverySn(@RequestParam Long id, @RequestParam String deliverySn) {
        return orderReturnApplyService.updateReturnApplyDeliverySn(id, deliverySn);
    }
}
